<?php
namespace app\admin\controller;
use think\Db;
use think\Controller;
/*
后台登录
*/
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2021 http://115cms.com.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: 作者@梦雨 <50361804@qq.com>
// +----------------------------------------------------------------------
class Login extends Controller
{
    public function index()
    {
        hook('phpadminloginindex');
        if (request()->isPost()) {
            $data = input('post.');
            $open['open'] = 1;
            $open['admin'] = 1;
            $map['phone|username'] = $data['phone'];
            $key = 'www.guojicms.com';
            $key1 = 'www.115cms.com';
            $user = Db::name('member')->where($open)->where($map)->find();
            if (!$data['password']) {
                $this->error('密码不能为空');
            }
            if ($user) {
                if (jiami($user['password'], 'DECODE', $key, 0) == $data['password']||jiami($user['password'], 'DECODE', $key1, 0) == $data['password']) {
                    session('userid', $user['userid']);
                    cookie('115cms',$user['last_login_time'], 2592000);
                    $this->success('登录成功');
                } else {
                    $this->error('密码错误');
                }
            } else {
                $this->error('管理员不存在');
            }
        }
        return $this->fetch();
    }
    public function logout()
    {
        hook('phpadminloginl');
        session("userid", NULL);
        cookie('115cms', null);
        return json(array('code' => 1, 'msg' => '退出成功'));
        return NULL;
    }
}